<?php

	/*
		Class Name: rtmsEvent
		Description: Tracks events occurred in the system.
		Created On: March 16, 2014
		Created By: Lenin Rodríguez
		History:
		
	*/
	
	require_once ('../libs/dbConnector.php');
	
	abstract class rtmsEventLevel{
			const information = 1;
			const warning = 2;
			const error = 3;
		}
	
	class rtmsEvent {
			var $dbConn;
			var $message;
						
			function rtmsEvent(){
					$this->message = '';
			}
			function message(){return $this->message;}
			
			function addEvent($userName, $source, $datetime, $message, $level){
				$boolres = false;
				$dbConn = new dbConnector();				
				if ($dbConn->openConnection()){													   
					$query = 'insert into rtmsevent (username,source,eventDate,eventMessage,eventLevel,recordDate) values '.
							  '(\''.$userName.'\',\''.$source.'\',\''.$datetime.'\',\''.$message.'\','.$level.',now())';

					$dbConn->query($query);			
					$boolres = true;
				}else{
					$message = "Error: ". $dbConn->message();
					$boolres = false;}
			$dbConn->closeConnection();
			return $boolres;
			}
			
		}
?>